//
//  ViewController.m
//  map
//
//  Created by lsy on 15/11/16.
//  Copyright © 2015年 刘世玉. All rights reserved.
//

#import "ViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<CLLocationManagerDelegate, MKMapViewDelegate>

@property(nonatomic, strong)CLLocationManager *manager;
@property(nonatomic, strong)MKMapView *mapView; //地图

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initMapView];
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)initMapView
{
    [self initmanager];
    self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    self.mapView.mapType = MKMapTypeStandard;
    [self.view addSubview:self.mapView];

    //设置地图显示的区域 （给一个中心位置）
    //给一个经纬度 和 缩放比例（0.01 -- 0.05）
    //34.77274892， 113，67591140
    self.mapView.region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(34.77274892, 113.67591140), MKCoordinateSpanMake(0.01, 0.01));
    //是否显示，用户位置
    self.mapView.showsUserLocation = YES;
    //设置代理
    self.mapView.delegate = self; //可以操作点标注
    //粘贴地图
    
    //增加大头针
    [self createAnnotation];
    
    
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    [self.mapView addGestureRecognizer:longPress];
}


- (void)longPress:(UILongPressGestureRecognizer*)longPress
{
    
}

- (void)createAnnotation
{
    //实例化一个点标注 （点标注（大头针）数据）
    //这个对象实际上就是一个数据模型
    MKPointAnnotation *annotation1 = [[MKPointAnnotation alloc] init];
    //设置经纬度
    annotation1.coordinate = CLLocationCoordinate2DMake(34.77274892, 113.67591140);
    //主标题
    annotation1.title = @"主标题";
    //副标题
    annotation1.subtitle = @"副标题";
    //增加到地图上
    [self.mapView addAnnotation:annotation1];
}

- (void)initmanager
{
    if (self.manager) {
        return;
    }
    
    self.manager = [[CLLocationManager alloc] init];
#ifdef __IPHONE_8_0
    //判断版本
    if ([self.manager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        {
            //有就调用
            [self.manager performSelector:@selector(requestAlwaysAuthorization)];
        }
        self.manager.delegate = self;
    }
#endif
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    NSLog(@"啦啦啦");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
